function countDiffSubStr(s : string) : longint;

var
	i, k, kk, cc, ls : longint;  
	p, h, a : array[0..2010] of int64;  

	procedure sort(l, r : longint);

	var
		i, j : longint;
		x, y : int64;

	begin
		i := l;
		j := r;
		x := a[l + random(r - l + 1)];
		repeat
			while a[i] < x do inc(i);
			while a[j] > x do dec(j);
			if i <= j then begin
				y := a[i];
				a[i] := a[j];
				a[j] := y;
				inc(i);
				dec(j);
			end;
		until i > j;
		if l < j then sort(l, j);
		if i < r then sort(i, r);
	end;

begin
	ls := length(s);
	p[0] := 1;
	for i := 1 to ls do
		p[i] := p[i - 1] * 31;
	h[0] := 0;
	for i := 1 to ls do
		h[i] := h[i - 1] + ord(s[i]) * p[i];
	result := 0;
	for k := 1 to ls do begin
		cc := 0;
		kk := ls - k + 1;
		for i := 1 to kk do begin
			inc(cc);
			a[cc] := (h[i + k - 1] - h[i - 1]) * p[ls - i];	
		end;
		if cc > 0 then sort(1, cc); 
		inc(result, byte(cc > 0));
		for i := 2 to cc do
			inc(result, byte(a[i] > a[i - 1])); 
	end;
end;